home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.inap.net!news1!ind-001-236-76
- From: dlmiller@iquest.net (Doug Miller)
- Subject: Re: reversing a string
- X-Nntp-Posting-Host: ind-001-236-76.iquest.net
- Message-ID: <DpnFtK.C1w@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <4k6cjl$j8f@central.server.swt.edu> <4k6jks$fh9@solutions.solon.com> <DpLtt5.Lqu@iquest.net> <829135845snz@genesis.demon.co.uk>
- Date: Wed, 10 Apr 1996 13:53:45 GMT
-
- Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >In article <DpLtt5.Lqu@iquest.net> dlmiller@iquest.net "Doug Miller" writes:
- >
- >>seebs@solutions.solon.com (Peter Seebach) wrote:
- >>>I can't see a way to reverse in place without a temporary of some sort,
- >>>or a loop of some sort, or something which is fundementally equivalent
- >>>to one of those. There may be one, but I don't know it.
- >>>
- >>>-s
- >>
- >>How about this:
- >>
- >>void swap (char *s) {
- >> if (strlen(s) > 1) {
- >
- >strlen() is fundamentally based on a loop.
- >
- >--
- >-----------------------------------------
- >Lawrence Kirby | fred@genesis.demon.co.uk
- >Wilts, England | 70734.126@compuserve.com
- >-----------------------------------------
-
- OK, since the objective is to determine if the string is more than 1 character long, we can do
- the same by testing the next character.
- Replace
- if (strlen(s) > 1)
- with
- if (*(s + 1))
- and the rest of the algorithm is still valid.
-